package zhongbo.java.air.ingestion.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.ingestion.dto.FlightPathDto;
import zhongbo.java.air.ingestion.model.AirFlightPath;
import zhongbo.java.air.ingestion.service.IAirIngestionService;
import zhongbo.java.air.ingestion.repository.FlightPathDtoRepository;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class AirIngestionServiceImpl implements IAirIngestionService {

    @Autowired
    private FlightPathDtoRepository flightPathDtoRepository;

    @Override
    public String publishInDB(FlightPathDto flightPathDto) {
        if (flightPathDto == null) {
            throw new RuntimeException("传进来的数据传输对象为空");
        }
        AirFlightPath airFlightPath = new AirFlightPath();
//        airFlightPath.setId(flightPathDto.getId());
//        airFlightPath.setIcaoCode(flightPathDto.getIcao_code());
//        airFlightPath.setTimestamp(flightPathDto.getTimestamp());
//        airFlightPath.setLatitude(flightPathDto.getLatitude());
//        airFlightPath.setLongitude(flightPathDto.getLongitude());
//        airFlightPath.setAltitude(flightPathDto.getAltitude());
//        airFlightPath.setSpeed(flightPathDto.getSpeed());
//        airFlightPath.setHeading(flightPathDto.getHeading());
//        airFlightPath.setSourceType(flightPathDto.getSource_type());

        BeanUtils.copyProperties(flightPathDto,airFlightPath);

        int insert = flightPathDtoRepository.insert(airFlightPath);
        if (insert > 0) {
            return flightPathDto.getId();
        }
        throw new RuntimeException("插入信息失败");
    }

//    @Override
//    public PageVo<FlightPathDto> pageFlightPathAll(String icao, Date startTime, Date endTime,
//                                                   Integer pageNumber, Integer pageSize) {
//        QueryWrapper<AirFlightPath> queryWrapper = new QueryWrapper();
//        if (StrUtil.isNotBlank(icao)) {
//            queryWrapper.like("icao_code",icao).between("timestamp",startTime,endTime);
//        }
//        IPage pageParam = new Page(pageNumber,pageSize);
//        IPage airIngestion = flightPathDtoRepository.selectPage(pageParam,queryWrapper);
//        return new PageVo<>(airIngestion);
//    }
}
